<style lang='scss' scoped>
@import "@/assets/css/variable";
.addStaff {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  background-color: $main-bgc;
  min-height: 100%;
  font-size: 1.2rem;
  overflow: auto;
  box-sizing: border-box;
  .header-box {
    border-bottom: 1px solid $border-c;
    background-color:white;
    padding: 1.4rem 1.7rem;
    .title {
      font-size: 1.8rem;
    }
  }
}
</style>
<template>
  <div class="addStaff padding-all-m">
    <div class="header-box border-r-l">
      <div class="title t-bold">添加核销员</div>
      <van-field
          required
          v-model="form.name"
          label="姓名"
          placeholder="请填写您的姓名"
          input-align="right"
        />
      <van-field
          required
          v-model="form.mobile"
          label="手机号"
          placeholder="请填写您的手机号"
          input-align="right"
        />
    </div>
    <div class="add-box margT-l">
      <van-button :color="$store.getters.getMasterColor" block @click="getVerificationSave">提交</van-button>
    </div>
  </div>
</template>

<script>
import { Button, Icon, Field, Dialog } from "vant";
export default {
  name:'StaffManage',
  components: {
    [Icon.name]: Icon,
    [Button.name]: Button,
    [Field.name]: Field,
    [Dialog.name]: Dialog
  },
  data() {
    return {
      status: 1,
      // openid: '',
      // merchant_id: '',
      // nickname: '',
      // avatar: '',
      form: {
        name: '', // 需手动填写
        mobile: '' // 需手动填写
      }
    };
  },
  computed: {
    // getOpenid() {
    //   return this.$store.state.openid
    // }
  },
  // watch: {
  //   getAppid (newCount, oldCount) {
  //    // Our fancy notification (2).
  //    console.log(`We have ${newCount} openid now, yaay!`)
  //   }
  // },
  mounted() {
    console.log("addstaff mounted")
    console.log("openid", this.$store.state.openid)
    // this.openid = this.openid,
    // this.merchant_id = this.$route.query.merchant_id,
    // this.nickname = this.$route.query.nickname,
    // this.avatar = this.avatar,
    // this.name = this.name, // 需手动填写
    // this.mobile = this.mobile // 需手动填写
  },
  methods: {
    getVerificationSave() {
      const _this = this;
      let params = {
        openid: this.$store.state.openid,
        merchant_id: this.$route.query.merchant_id,
        nickname: this.$store.state.userInfo.nickname,
        avatar: this.$store.state.userInfo.avatar,
        name: this.form.name, // 需手动填写
        mobile: this.form.mobile // 需手动填写
      }
      console.log("params", params)
      this.$request.getVerificationSave(params).then(res=>{
        if(res.ret==200){
          Dialog.alert({
            title: '系统提示',
            message: '添加成功',
          }).then(() => {
            // on close
            _this.$router.replace('/staffManage')
          });
        }else{
          Dialog.alert({
            title: '系统提示',
            message: res.msg
          }).then(() => {
            // on close
          });
        }
      })
    }  
  },
};
</script>